/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.component.gateway.dianlan.protocol.passive;

import info.peigen.hotpot.common.core.enums.StubType;
import info.peigen.hotpot.component.gateway.dianlan.annotations.DianlanProtocol;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import lombok.experimental.FieldDefaults;
import lombok.experimental.SuperBuilder;

import static info.peigen.hotpot.component.gateway.dianlan.annotations.DianlanProtocol.DianlanProtocolDataType.*;

/**
 * <b>(DianlanBmsAndLiquidCoolingUnit)</b>
 * <p>
 * BMS及液冷机组通讯协议——总状态参数上传到后台服务端
 * 传送间隔 10 秒周期上送
 * 帧类型码 0xEF(239)
 * 序列号域
 * 数据长度 90
 * 帧校验域
 *
 * @author LiDaHai
 * @version 1.0.0
 * @since 2023/1/12
 */
@SuperBuilder
@Data
@NoArgsConstructor
@AllArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE)
@Accessors(chain = true)
public class DianlanBmsAndLiquidCoolingUnit {
    /** 桩编码 */
    @DianlanProtocol(length = 7, start = 0, end = 7, dataType = BCD)
    String                                   stubNo;
    /** 桩类型 */
    @DianlanProtocol(length = 1, start = 7, end = 8, dataType = ENUM)
    StubType                                 stubType;
    /** 充电枪数量 */
    @DianlanProtocol(length = 1, start = 8, end = 9, dataType = BIN)
    Integer                                  chargingCount;
    /** 充电枪号 */
    @DianlanProtocol(length = 1, start = 9, end = 10, dataType = BCD)
    String                                   chargingPortNo;
    /** 电池组状态 8字节 */
    @DianlanProtocol(length = 8, start = 10, end = 18, dataType = OBJ, dataTypeClass = "DianlanBatteryPackStatusInfoParserBits")
    DianlanBatteryPackStatusInfo             batteryPackStatusInfo;
    /** 单体电池状态 8字节 */
    @DianlanProtocol(length = 8, start = 18, end = 26, dataType = OBJ, dataTypeClass = "DianlanBatteryStatusInfoReasonBits")
    DianlanBatteryStatusInfo                 batteryInfo;
    /** 单体电池温度 8字节 */
    @DianlanProtocol(length = 8, start = 26, end = 34, dataType = OBJ, dataTypeClass = "DianlanBatteryTemperatureInfoReasonBits")
    DianlanBatteryTemperatureInfo            batteryTemperatureInfo;
    /** 电池绝缘电阻 8字节 */
    @DianlanProtocol(length = 8, start = 34, end = 42, dataType = OBJ, dataTypeClass = "DianlanBatteryInsulationResistanceInfoReasonBits")
    DianlanBatteryInsulationResistanceInfo   batteryInsulationResistanceInfo;
    /** 直流充电时电机报文 8字节 */
    @DianlanProtocol(length = 8, start = 42, end = 50, dataType = OBJ, dataTypeClass = "DianlanDcStubDataGramReasonBits")
    DianlanDcStubDataGram                    dianlanDcStubDataGram;
    /** BMS转发充直流充电时电机报文 8字节 */
    @DianlanProtocol(length = 8, start = 50, end = 58, dataType = OBJ, dataTypeClass = "DianlanDcStubForwardDataGramReasonBits")
    DianlanDcStubForwardDataGram             dianlanDcStubForwardDataGram;
    /** 充电插座温度报文 8字节 */
    @DianlanProtocol(length = 8, start = 58, end = 66, dataType = OBJ, dataTypeClass = "DianlanChargingSocketTemperatureDataGramReasonBits")
    DianlanChargingSocketTemperatureDataGram chargingSocketTemperatureDataGram;
    /** 电池严重高温箱体号报文 8字节 */
    @DianlanProtocol(length = 8, start = 66, end = 74, dataType = OBJ, dataTypeClass = "DianlanBatteryHighTemperatureBoxDataGramReasonBits")
    DianlanBatteryHighTemperatureBoxDataGram batteryHighTemperatureBoxDataGram;
    /** 水冷机组控制报文 8字节 */
    @DianlanProtocol(length = 8, start = 74, end = 82, dataType = OBJ, dataTypeClass = "DianlanWaterCoolingUnitControlDataGramReasonBits")
    DianlanWaterCoolingUnitControlDataGram   waterCoolingUnitControlDataGram;
    /** 水冷机组状态报文 8字节 */
    @DianlanProtocol(length = 8, start = 82, end = 90, dataType = OBJ, dataTypeClass = "DianlanWaterCoolingUnitStatusDataGramReasonBits")
    DianlanWaterCoolingUnitStatusDataGram    waterCoolingUnitStatusDataGram;

    @Override
    public String toString() {
        return "桩编码：" + stubNo + "," +
                "桩类型：" + stubType.getMessage() + "，" +
                "充电枪数量：" + chargingCount + "，" +
                "充电枪号：" + chargingPortNo + "，\n" +
                "电池组状态[" + batteryPackStatusInfo + "]，\n" +
                "单体电池状态[" + batteryInfo + "]，\n" +
                "单体电池温度[" + batteryTemperatureInfo + "]，\n" +
                "电池绝缘电阻[" + batteryInsulationResistanceInfo + "]，\n" +
                "直流充电时电机报文[" + dianlanDcStubDataGram + "]，\n" +
                "BMS转发充直流充电时电机报文[" + dianlanDcStubForwardDataGram + "]，\n" +
                "充电插座温度报文[" + chargingSocketTemperatureDataGram + "]，\n" +
                "电池严重高温箱体号报文[" + batteryHighTemperatureBoxDataGram + "]，\n" +
                "水冷机组控制报文[" + waterCoolingUnitControlDataGram + "]，\n" +
                "水冷机组状态报文[" + waterCoolingUnitStatusDataGram + "]";
    }
}